package daa.levelup.Library;

import java.util.Iterator;
import java.util.List;
import com.mysql.jdbc.Driver;


public class TestDaoLibrary {

    private static DaoLibrary daoLibrary;

    public static void main(String[] args) {
        try {
            System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            daoLibrary = new DaoLibrary();
            List<Book> fromDb = daoLibrary.getAllBooksFromDB();
            showUsers(fromDb);
            Book newBook = new Book(3, "UnmaterialBook");
            boolean res = daoLibrary.addBookToDB(newBook);
            System.out.println("RES: " + res);
            fromDb = daoLibrary.getAllBooksFromDB();
            showUsers(fromDb);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void showUsers(List<Book> all) {
        Iterator<Book> iter = all.iterator();
        Book tmp;
        while (iter.hasNext()) {
            tmp = iter.next();
            System.out.println(tmp);
        }
    }
}
